﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using QianBuo.Lottery.Web.Models;
using Code.BLL;
using Code.Models;
using Code.Commen;

namespace QianBuo.Lottery.Web.Controllers
{
    public class HomeController : BaseController
    {
        //
        // GET: /Home/

        public ActionResult Index([Bind(Exclude="nc")]IndexModel model)
        {
            model.nc = CacheManage.NoticeCount;
            if (model.nc > 0)
            {
                int pagesize = CacheManage.OptionSite[Option_Site_Key.Site_Notice_HomeCount].ToInt32(5);
                if (model.id == null || model.id < 1)
                    model.id = 1;
                if (model.s == null || model.s < 1)
                    model.s = pagesize;
                if (model.id > 1 || model.s != pagesize)
                {
                    var CM = new CommenManage<Notice>();
                    model.Notices = CM.Select(s => s.Where(p => p.State == (short)NoticeState.Show)
                        .Select(p => new Key<string, string, bool>(p.Title, p.Message, p.HighLight))
                        .Skip(model.s.Value * (model.id.Value - 1)).Take(model.s.Value));
                }
                else
                {
                    model.Notices = CacheManage.TopNotices.Values.OrderByDescending(p=>p.AddTime)
                      .Select(p => new Key<string, string, bool>(p.Title, p.Message, p.HighLight));
                }
            }
            return View(model);
        }

    }
}
